<script setup>
import pageCom from '@/components/pagecontainer.vue'
import { onMounted, ref } from 'vue'
import { userStore } from '@/stores';
import { userUpdateInfoService } from '@/api/user'
const { user: { email, id, nickname, username }, getUser } = userStore()
const title = ref('基本资料')
const form = ref()
const formModel = ref({
  id,
  username,
  nickname,
  email
})
const rules = ref({
  username: [
    { required: true, message: '请输入泥称', trigger: 'blur' },

  ]
  , nickname: [
    { required: true, message: '请输入泥称', trigger: 'blur' },
    { pattern: /^\S{2,11}$/, message: '长度在2到11之间', trigger: 'blur' }
  ],
  email: [
    { required: true, message: '请输入邮箱', trigger: 'blur' },
  ]
})
const submitform = async () => {
  await form.value.validate()
  await userUpdateInfoService(formModel.value)
  getUser()
  ElMessage.success('修改成功')
}
</script>

<template>
  <pageCom :title="title">
    <el-form ref="form" :model="formModel" :rules="rules" class="form" label-width="100px">
      <el-form-item label="登录名称 " prop="username">
        <el-input v-model="formModel.username"></el-input>
      </el-form-item>
      <el-form-item label="用户昵称 " prop="nickname">
        <el-input v-model="formModel.nickname"></el-input>
      </el-form-item>
      <el-form-item label="用户邮箱 " prop="email">
        <el-input v-model="formModel.email"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitform">提交修改</el-button>
      </el-form-item>
    </el-form>
  </pageCom>
</template>
<style lang="scss" scope>
.form {
  margin: 0 auto;
  width: 80%;
}
</style>